﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication1
{
    public class QueueTwoStacks<T>
    {
        private Stack<T> inbox = new Stack<T>();
        private Stack<T> outbox = new Stack<T>();

        public void Enqueue(T item)
        {
            inbox.Push(item);
        }

        public T Dequeue()
        {
            if (outbox.Count == 0)
            {
                while (inbox.Count != 0)
                {
                    outbox.Push(inbox.Pop());
                }
            }
            return outbox.Pop();
        }
    }

    public class QueueOneStack<T>
    {
        private Stack<T> inbox = new Stack<T>();

        public void Enqueue(T item)
        {
            if (inbox.Count != 0)
            {
                T topItem = inbox.Pop();
                Enqueue(item);
                inbox.Push(topItem);
            }
            else
            {
                inbox.Push(item);
            }
        }

        public T Dequeue()
        {
            return inbox.Pop();
        }
    }
}
